﻿<UserControl x:Class="Updater.Wpf.Controls.UpdaterStatusControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:viewModels="clr-namespace:Updater.Wpf.ViewModels" xmlns:wpf="clr-namespace:Updater.Wpf"
             xmlns:utils="clr-namespace:Updater.Wpf.Utils"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance viewModels:UpdaterViewModel}">
    <UserControl.Resources>
        <Style x:Key="HyperlinkLikeButton" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <ControlTemplate.Resources>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="TextDecorations" Value="Underline" />
                                    </Style>
                                </ControlTemplate.Resources>
                                <ContentPresenter />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <StackPanel Orientation="Horizontal">
        <Image Width="16" Height="16">
            <Image.Style>
                <Style TargetType="Image">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Status}" Value="{x:Static wpf:UpdateStatus.UpdateFailed}">
                            <Setter Property="Source"
                                    Value="pack://application:,,,/Updater.Wpf;component/Resources/Icons/arrow_turn_090_left.png" />
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Status}" Value="{x:Static wpf:UpdateStatus.UpdateSucceed}">
                            <Setter Property="Source"
                                    Value="pack://application:,,,/Updater.Wpf;component/Resources/Icons/tick_shield.png" />
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Status}"
                                     Value="{x:Static wpf:UpdateStatus.UpdateIsReadyToInstall}">
                            <Setter Property="Source"
                                    Value="pack://application:,,,/Updater.Wpf;component/Resources/Icons/exclamation_shield.png" />
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ErrorOccurred}" Value="True">
                            <Setter Property="Source"
                                    Value="pack://application:,,,/Updater.Wpf;component/Resources/Icons/cross_circle.png" />
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Image.Style>
        </Image>
        <TextBlock Text="{Binding StatusText}" VerticalAlignment="Center" Margin="3">
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding CanShowStatusDetails}" Value="true">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <Button Style="{StaticResource HyperlinkLikeButton}" Margin="3" Content="{Binding StatusText}"
                VerticalAlignment="Center" Command="{Binding ShowStatusDetailsCommand}"
                Visibility="{Binding CanShowStatusDetails,Converter={utils:BooleanToVisibilityConverterExtension}}" />
    </StackPanel>
</UserControl>